package com.aaa.demo10;

import java.util.concurrent.*;

/**
 * @author ${崔灿}
 * @date 2022/11/02 19:54
 **/

public class Test01 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        //创建一个callable类型的任务对象
//        MyCallAble myCallAble = new MyCallAble();
//        //把任务返回的结果也封装到Ftureask对象中
//        FutureTask futureTask = new FutureTask(myCallAble);
//        //创建一个线程对象，把上面的任务交予该线程对象
//        Thread thread = new Thread(futureTask);
//        thread.start();
//        System.out.println(thread.getName());

        ExecutorService executorService = Executors.newFixedThreadPool(2);

        Future<Integer> future = executorService.submit(new MyCallAble());
        executorService.shutdown();
        System.out.println(future.get());

    }
}
class MyCallAble implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 0; i <=100 ;i++) {
            sum += i;
        }
        return sum;
    }
}
